import { math } from "cc";
import { BaseView, UIOrder } from "../../mvc/base_view";

export class PutBoomView extends BaseView{
    constructor(){
        super();
        this.ui_package = "main";
        this.layout_name = "ui_put_boom_view";
        this.order = UIOrder.MainUp;
    }

    OpenViewCallback(...args: any[]){
        let card_type_list = args[0];
        let close_callback = args[1];
        this.GetGButton("random_btn").onClick(()=>{
            let put_index = math.randomRangeInt(0, card_type_list.length);
            close_callback(put_index);
            this.Close();
        });

        for (let index = 1; index <= 5; index++) {
            let btn = this.GetGButton("positon_btn" + index);
            if(index <= card_type_list.length){
                btn.grayed = false;
                btn.touchable = true;
                btn.onClick(()=>{
                    let put_index = card_type_list.length - index + 1;
                    close_callback(put_index);
                    this.Close();
                })  
            }else{
                btn.grayed = true;
                btn.touchable = false;
            }
        }

        this.GetGButton("positon_btn6").onClick(()=>{
            close_callback(0);
            this.Close();
        });

    }
}